import BaseGroup from '@/components/js/BaseGroup'
import { EventBus } from '@/store/index'
import { CONTROL_TYPES } from '@/common/const-wb'

export default class GradeChange extends BaseGroup {
  constructor() {
    super();
    //子类覆盖
  }

  start() {
    //参数：{"relateCompId":"32fb760e-ae22-4bce-a6c1-2b58262adbfd","levelVip":{"0":0,"50":1,"100":2}}
    //页面刷新
    EventBus.$on('refreshDynamicData', () => {
      this.refreshMap();
    });
    this.refreshMap();
  }
  refreshMap(){
    let relateCompId = this.item.interactionData.injectJsClassObj.relateCompId
    let gradeObj = this.item.interactionData.injectJsClassObj.levelVip
    let gradeScore = this.controls[relateCompId][CONTROL_TYPES.number].data.num //通过计数获取积分
    let vipKeys = _.keys(gradeObj);

    _.forEach(this.components, (compData) => {
      if(compData.commonAttr.isVisible){//只更新显示可见的组件
        let spriteSheetObj = {
          currentStep: null
        };
        _.forEach(vipKeys, (k) => {
          if(gradeScore >= k){
            spriteSheetObj.currentStep = gradeObj[k]
          }
        })
        this.store.commit("updateComponentAttr", {
          id: compData.id,
          interactionData: { spriteSheetObj },
        });
        EventBus.$emit('refreshImgSpriteSheet', { id: compData.id });
      }
    });
  }

  destroy() {
    super.destroy();
  }
}
